package com.atguigu.bigdata.spark.zzgcore.rdd.operator.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Classname Spark_01_RDD_Operator_Action
 * @Description TODO
 * @Date 2023/10/22 21:22
 * @Author zhuzhenguo
 */
object Spark_03_RDD_Operator_Action {
  def main(args: Array[String]): Unit = {
    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)

    //aggregateByKey:初始值只会参与分区内计算
    //aggregate：初始值会参与分区内计算，并且会参与分区间计算
    // 10 + 13 + 17
//    val result: Int = rdd.aggregate(10)(_ + _, _ + _)
    val result: Int = rdd.fold(10)(_ + _)
    println(result)
    sc.stop()
  }
}
